#pragma once
extern const int maxSize;

int isMatched(char left, char right) {
	if (left == '(' && right == ')' ||
		left == '[' && right == ']' ||
		left == '{' && right == '}' ||
		left == '<' && right == '>')
		return 1;
	else
		return 0;
}

int isParenthesesBalanced(char exp[]) {
	char s1[maxSize];
	int top = -1;
	for (int i = 0; exp[i] != '\0'; i++) {
		if (exp[i] == '(' || exp[i] == '[' || exp[i] == '{' || exp[i] == '<') {
			s1[++top] = exp[i];
		}
		else if(exp[i] == ')' || exp[i] == ']' || exp[i] == '}' || exp[i] == '>'){
			if (top == -1)
				return 0;
			else
			{
				char left = s1[top--];
				if (!isMatched(left, exp[i]))
					return 0;
			}
		}
	}
	if (top > -1)
		return 0;
	return 1;
}